package datastructure_algorithm.set;

import java.util.ArrayList;

public class _Test {

	public static void main(String[] args) {
//		testBSTSet();
//		testLinkedListSet();
		
		String filename = "/home/zc/git/learn-java/src/main/resources/pride-and-prejudice.txt";
		System.out.println("BSTSet: " + testSet(new BSTSet<String>(), filename) + "s");
		System.out.println();
		System.out.println("LinkedListSet: " + testSet(new LinkedListSet<String>(), filename) + "s");
	}
	
	private static double testSet(Set<String> set, String filename) {
		long s = System.nanoTime();
		System.out.println(filename);

		ArrayList<String> words1 = new ArrayList<>();
        if(FileOperation.readFile(filename, words1)) {
            System.out.println("Total words: " + words1.size());

            for (String word : words1)
                set.add(word);
            System.out.println("Total different words: " + set.getSize());
        }
        long e = System.nanoTime();
		return (e - s) / 1000000000.0;
	}

	private static void testBSTSet() {
		System.out.println("Pride and Prejudice");

		ArrayList<String> words1 = new ArrayList<>();
        if(FileOperation.readFile("/home/zc/git/learn-java/src/main/resources/pride-and-prejudice.txt", words1)) {
            System.out.println("Total words: " + words1.size());

            BSTSet<String> set1 = new BSTSet<>();
            for (String word : words1)
                set1.add(word);
            System.out.println("Total different words: " + set1.getSize());
        }

        System.out.println();


        System.out.println("A Tale of Two Cities");

        ArrayList<String> words2 = new ArrayList<>();
        if(FileOperation.readFile("/home/zc/git/learn-java/src/main/resources/a-tale-of-two-cities.txt", words2)){
            System.out.println("Total words: " + words2.size());

            BSTSet<String> set2 = new BSTSet<>();
            for(String word: words2)
                set2.add(word);
            System.out.println("Total different words: " + set2.getSize());
        }
	}

	private static void testLinkedListSet() {
		System.out.println("Pride and Prejudice");

        ArrayList<String> words1 = new ArrayList<>();
        if(FileOperation.readFile("/home/zc/git/learn-java/src/main/resources/pride-and-prejudice.txt", words1)) {
            System.out.println("Total words: " + words1.size());

            LinkedListSet<String> set1 = new LinkedListSet<>();
            for (String word : words1)
                set1.add(word);
            System.out.println("Total different words: " + set1.getSize());
        }

        System.out.println();


        System.out.println("A Tale of Two Cities");

        ArrayList<String> words2 = new ArrayList<>();
        if(FileOperation.readFile("/home/zc/git/learn-java/src/main/resources/a-tale-of-two-cities.txt", words2)){
            System.out.println("Total words: " + words2.size());

            LinkedListSet<String> set2 = new LinkedListSet<>();
            for(String word: words2)
                set2.add(word);
            System.out.println("Total different words: " + set2.getSize());
        }
	}
}
